package com.maoyu.cloud.api.service.impl;

import com.maoyu.cloud.api.entity.LoginEntity;
import com.maoyu.cloud.api.mapper.ApiMapper;
import com.maoyu.cloud.api.service.ApiService;
import com.maoyu.cloud.api.utils.MD5Utils;
import com.maoyu.cloud.login.entity.LoginUserEntity;
import com.maoyu.cloud.mybatis.entity.PtUserEntity;
import com.maoyu.cloud.spring.util.CloudUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ApiServiceImpl implements ApiService {

    @Resource
    private ApiMapper apiMapper;
    /**
     * @param loginUserEntity
     * @return
     */
    @Override
    public PtUserEntity login(LoginEntity loginUserEntity) {
        loginUserEntity.setPassword(MD5Utils.encode(loginUserEntity.getPassword()));
        return apiMapper.login(loginUserEntity);
    }

    /**
     * @param ptUserEntity  用户信息
     * @return 1:注册成功 0:注册失败
     */
    @Override
    public int register(PtUserEntity ptUserEntity) {
        ptUserEntity.setUserUuid(CloudUtil.generateUuid());
        ptUserEntity.setPassword(MD5Utils.encode(ptUserEntity.getPassword()));
        return apiMapper.register(ptUserEntity);
    }
}
